package com.yww.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yww.entity.Auto;
import com.yww.service.IAutoService;
import com.yww.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 *  自动分配
 * </p>
 *
 * @author 雯雯yang
 * @since 2020-06-04
 */
@RestController
@RequestMapping("/auto")
public class AutoController {
    @Autowired
    IAutoService service;

    @RequestMapping("/getauto")
    public Object getauto() {
        System.out.println("aa");
        Auto one = service.getOne(new QueryWrapper<Auto>().eq("auto_id", 1));
        System.out.println("bb");
        return one;
    }

    @RequestMapping("/updateauto")
    public Object updateauto(Integer num) {
        System.out.println(num);
        Auto auto=new Auto();
        auto.setYesNo(num);
        auto.setAutoId(1);
        boolean updateById = service.update(auto,new QueryWrapper<Auto>().eq("auto_id",auto.getAutoId()));
        if(num==0) {
            if (updateById) {
                return new Result(0, "自动分配开启");
            }
            return new Result(1,"自动分配开启失败");
        }else {
            if (updateById) {
                return new Result(0, "自动分配关闭");
            }
            return new Result(1, "自动分配关闭失败");
        }
    }

    public Object test(){
        return null;
    }

}
